import instance from "./instance";

export function reqGetLunbo() {
  return instance({
    url: "/api/getlunbo",
  });
}
// 获取轮播图数据
export function reqRecommend(page = 1, pagesize = 10) {
  return instance({
    url: `/api/recommend?page=${page}&limit=${pagesize}`,
  });
}
// 获取商品数据
export function reqGetPagGoods(page = 1, pagesize = 10) {
  return instance({
    url: `/api/getListgoods?page=${page}&pagesize=${pagesize}`,
  });
}
// 获取商品的图片
export function reqGetGoodsImg(id) {
  return instance({
    url: `/api/getthumbimages/${id}`,
  });
}
// 或取商品的详情
export function reqGetParticulars(id) {
  return instance({
    url: `/api/getgoodsinfo/${id}`,
  });
}
// 获取商品分类
export function getCategory() {
  return instance({
    url: `/api/getcategory`,
  });
}
// 获取分类数据
export function getCategoryGoods(id) {
  return instance({
    url: `/api/getcategorygoods?category_id=${id}`,
  });
}

// 获取新闻列表
export function getNewsList(page, pagesize) {
  return instance({
    url: `/api/getnewslist?page=${page}&pagesize=${pagesize}`,
  });
}

// 获取单个新闻
export function getOneNews(id) {
  return instance({
    url: `/api/getnew/${id}`,
  });
}

//获取新闻评论
export function getNewsComments(id, pageindex) {
  return instance({
    url: `/api/getcomments/${id}?pageindex=${pageindex}`,
  });
}

//发布评论
export function pubCommit(id, content) {
  return instance({
    method: "post",
    url: `/api/postcomment/${id}`,
    data: { content },
  });
}

// 搜索
export function search(value, sort, page, pagesize) {
  return instance({
    url: `/api/search/?value=${value}&sort=${sort}&page=${page}&pagesize=${pagesize}`,
  });
}

// 获取购物车列表
export function getShopCarList(data) {
  return instance({
    url: `/api/getshopcarlist/${data}`,
  });
}

// 注册账户
export function register(option) {
  return instance({
    method: "post",
    url: `/api/register`,
    data: option,
  });
}

// 登录账户
export function login(option) {
  return instance({
    method: "post",
    url: `/api/login`,
    data: option,
  });
}

//上传头像
export function upload(formData) {
  return instance({
    method: "post",
    url: `/api/upload`,
    data: formData,
  });
}

// 获取用户地址
export function getAddress() {
  return instance({
    url: `/api/getaddress`,
  });
}

// 添加用户地址
export function incAddress(option) {
  return instance({
    method: "post",
    url: `/api/addaddress`,
    data: option,
  });
}

// 编辑用户地址
export function editAddress(id, option) {
  return instance({
    method: "post",
    url: `/api/updateaddress?address_id=${id}`,
    data: option,
  });
}

// 删除用户地址
export function delAddress(id) {
  return instance({
    method: "post",
    url: `/api/deladdress?address_id=${id}`,
  });
}

// 提交订单
export function commitOrder(option) {
  return instance({
    method: "post",
    url: `/api/commitorder`,
    data: option,
  });
}

// 获取订单信息
export function getOrderInfo(orderId) {
  return instance({
    method: "post",
    url: `/api/getorder?order_id=${orderId}`,
  });
}

// 获取用户订单
export function getuserOrder(page = 1, pagesize = 8) {
  return instance({
    method: "post",
    url: `/api/userorder`,
    params: {
      page,
      pagesize,
    },
  });
}

// 取消订单
export function cancelOrder(orderId) {
  return instance({
    method: "post",
    url: `/api/cancelorder?order_id=${orderId}`,
  });
}

// 取消订单
export function delOrder(orderId) {
  return instance({
    method: "post",
    url: `/api/delorder?order_id=${orderId}`,
  });
}

// 查看物流
export function materialFlow() {
  return instance({
    url: `/api/kuaidi`,
  });
}

// 查看二维码
export function getPayQrcode(orderId) {
  return instance({
    method: "post",
    url: `/api/payqrcode?order_id=${orderId}`,
  });
}

// 查询支付状态
export function getPayStatus(orderId) {
  return instance({
    method: "post",
    url: `/api/queryPayOrder?order_id=${orderId}`,
  });
}

// 刷新token
export function refreshToken(refreshToken) {
  return instance({
    method: "post",
    url: `/api/refreshToken`,
    data: { refreshToken },
  });
}

// 获取历史浏览
export function getHistory(option) {
  return instance({
    url: `/api/history`,
    params: option,
  });
}

// 获取历史浏览
export function addHistory(goods_id) {
  return instance({
    method: "post",
    url: `/api/addhistory?goods_id=` + goods_id,
  });
}

// 修改密码
export function updatePassword(newPassword) {
  return instance({
    method: "post",
    url: `/api/updatepassword?newPassword=` + newPassword,
  });
}
